# shows how lambda affects the histogram and the scatter plot

gg_color_hue <- function(n) {
  hues = seq(15, 375, length=n+1)
  hcl(h=hues, l=65, c=100)[1:n]
}

lambdas_hist <- function(X, lambdas.lim, xlim)
{
	lambdas <- seq(lambdas.lim[1], lambdas.lim[2], length=5)
	par(mfrow=c(2,5))
	colors <- gg_color_hue(2)
	first <- TRUE
	for(lambda in lambdas) {
		par(mar=c(0,0.9+1*first,2,0.1))
		smoothScatter(power_transform(X,lambda), ylim=xlim, xaxt='n', nrpoints=0, axes=FALSE)
		axis(side=2, labels=first)
		abline(0, 0, col='white')
		first <- FALSE
	}
	ylim <- c(0, 0.8)
	first <- TRUE
	for(lambda in lambdas) {
		par(mar=c(2,0.9+1*first,2,0.1))
		p <- seq(-10, +10, 0.1)
		plot(p, dnorm(p), type='l', lwd=2, col=colors[1], main=bquote(lambda == .(lambda)), xlim=xlim, ylim=ylim, axes=FALSE)
		box()
		axis(side=1)
		axis(side=2, labels=first)
		lines(p, dbhp(p), lwd=3, col=colors[2])

		h <- hist(power_transform(X,lambda), plot=FALSE, nclass=40)
		points(h$mids, h$density, pch=20)
		first <- FALSE
	}
}

